import cn.stylefeng.guns.sys.core.util.DateUtil;
import cn.stylefeng.guns.sys.modular.system.ApiEntity.*;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.codec.binary.Hex;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;
import java.security.MessageDigest;
import java.util.*;


public class test {
    //private static Object ParentvoBean;

    public static void main(String[] args) throws Exception {
//        BigDecimal xf=new BigDecimal(0.01);
//        System.out.println("xf:"+xf);
////        SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
////        Date date = new Date();
////        Calendar calendar = Calendar.getInstance();
////        calendar.setTime(date); // 设置为当前时间
////        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
////        date = calendar.getTime();
////        String accDate = format.format(date);
////        System.out.println("accDate:" + accDate);
////        String bz = "n99999";
////        bz = bz.substring(0, bz.indexOf("9"));
////        System.out.println("bz:" + bz);
////        String loanDate = "20170825";
////        SimpleDateFormat df=new SimpleDateFormat("yyyyMMdd");
////        SimpleDateFormat df1=new SimpleDateFormat("yyyy-MM-dd");
////        Date loanDate1=df.parse(loanDate);
////        String date1=df1.format(loanDate1);
////        System.out.println("date1:"+date1);
////
////        String sheetName="孙明洋";
////        String xm="";
////        //截取借款人名字
////        if(sheetName.contains("借款")){
////           xm=sheetName.substring(0, sheetName.indexOf("借款"));
////        }else{
////           xm=sheetName;
////        }
//
//        //System.out.println("xm:"+xm);
//
////        SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
////        Date date = new Date();
////        Calendar calendar = Calendar.getInstance();
////        calendar.setTime(date); // 设置为当前时间
////       // calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
////        calendar.add(Calendar.MONTH, -1);
////        date = calendar.getTime();
////        String accDate = format.format(date);
////        System.out.println("accDate:"+accDate);
////        System.out.println(UUIDUtils.getId());
//
//        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
//        ca.setTime(new Date());
//        ca.add(Calendar.DATE, -10);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟
//        String substring = sdf.format(ca.getTime());
//        System.out.println("substring:" + substring);
//
//        String str = "王伟强#622700220408113939";
////        str=str.substring(0,8);
////        System.out.println("str:"+str);
//        String str3 = str.split("[#]")[0];
//        String str4 = str.split("[#]")[1];
//        String str1 = str.substring(0, str.indexOf("#"));
//        String str2 = str.substring(str1.length() + 1);
//        System.out.println("str1:" + str1);
//        System.out.println("str2:" + str2);
//        System.out.println("str3:" + str3);
//        System.out.println("str4:" + str4);
//        String content = "20200701-20200708";
//        String beginTime = content.split("[-]")[0];
//        String endTime = content.split("[-]")[1];
//        System.out.println("beginTime:" + beginTime);
//        System.out.println("endTime:" + endTime);
//
//        String months = "2020-08-05";
//        String year = months.split("[-]")[0];
//        String month = months.split("[-]")[1];
//        String day = months.split("[-]")[2];
//        System.out.println("year:" + year);
//        System.out.println("month:" + month);
//        System.out.println("day:" + day);
//
//        // String dm="河北省邯郸市永年区新世纪";
//        String dm = "邯郸市永年区新世纪";
//
//        String dms[] = dm.split("河北省");
//
//        for (String s : dms) {
//            System.out.println("s:" + s);
//        }
//
////
////        MultiValueMap mailMap = new LinkedMultiValueMap();
////        mailMap.put("number", "1");
////        mailMap.put("number", "30");
////        mailMap.put("name", "wang");
////        mailMap.put("card", "12344");
////        mailMap.put("card", "65432");
////
////        Collection mapcoll =null ;
////        mapcoll = mailMap.ge;
////        Iterator ii = mapcoll.iterator();
////        while(ii.hasNext()){
////            String mailValue = (String) ii.next();
////            System.out.println(mailValue);
////        }
//        String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDwteCbSQgiIUwMZgX6Q5cGLCwH0i9Ou7bveU8JGuJcf416bVLpBZA6Hkdu47mxUETY3Bf4++yQ3khU0Il8JvtDp84AbAPEQI+qIoTF4Zm4Yytux6XLG8IYQWx1BBXNeDuuBl3d6q6cmgDz2zDX4IkF/HmAjBJuw3jCDMHwn/ZuNQIDAQAB";
//        // 调用方id
//        Integer productId = 1000002886;
//        // 版本号
//        String version = "1.0.0";
//        Integer pageNo = 1;
//        // 业务参数封装并加密
//        JSONObject obj = new JSONObject();
//        obj.put("companyId", 1000002886);
//        //获取消费类型的数据
//        List<Integer>list=new ArrayList<Integer>();
//        list.add(1);
//        list.add(2);
//        list.add(29);
//        list.add(30);
//        obj.put("tradeTypeIds", list);
//        String time=DateUtil.getStampNow();
//        obj.put("queryId", time);
//        obj.put("startTime", DateUtil.getYesterDay4Oclock());
//        obj.put("endTime", DateUtil.getToday4Oclock());
//        obj.put("callbackUrl", "aHR0cHM6Ly9ycy5iYW50aWFueWFvemcuY29tL2dvb2QvMS50eHQ=");
//
//
//
//        String sign = RsaUtil.encryptByPublicKey(obj.toJSONString(), publicKey);
//
//        System.out.println("sign:" + sign);
//
//        String password = Md5Util.md5s("717901chujunjun");
//
//        System.out.println("password:" + password);
//
//
//        String ip=ToolUtil.getIP();
//        System.out.println("ip:"+ip);
//
//        String times=  ToolUtil.currentTime();
////        System.out.println("times:"+times);
////        String strs="true12345";
////
////        System.out.println(strs.substring(strs.length() - 5));
//
//        StringBuilder sb=new StringBuilder();
//        sb=sb.append("true").append("135678");
//        System.out.println(sb.toString());
//        String strs[]=sb.toString().split("true");
//        System.out.println(strs[1]);
//
//        //String redirect_uri = "http://rs.bantianyaozg.com/wechat";
//        //String redirect_uri = "http://rs.bantianyaozg.com";
//        String redirect_uri = "http://liuxing125m.w3.luyouxia.net";
//
//            redirect_uri = URLEncoder.encode(redirect_uri, "UTF-8");
//        System.out.println("redirect_uri:"+redirect_uri);
//
//        String code="code=0711P4ml2Xfag743Vull2khm0E31P4mF&state=";
//
//        String url="https://rs.bantianyaozg.com";
//        BASE64Encoder encoder =new BASE64Encoder();
//        String encode = encoder.encode(url.getBytes());
//        System.out.println("encode:"+encode);
//
//
//        //String photoUrl = "https://crm7cdn.wuuxiang.com/export/zip/files/[1000002886-20210719110243]交易查询.zip";   //文件URL地址
//        String photoUrl = "https://crm7cdn.wuuxiang.com/export/zip/files/[1000002886-20210721144750]交易查询.zip";   //文件URL地址
//        String fileName = photoUrl.substring(photoUrl.lastIndexOf("/"));     //为下载的文件命名
//        System.out.println("filename:"+fileName);
//        String filePath = "D:/hyksj";      //保存目录
//        File file = saveUrlAs(photoUrl, filePath + fileName,"GET");
//        System.out.println("file:"+file);
//        System.out.println("startTime:"+ DateUtil.getYesterDay4Oclock());
//        System.out.println("endTime:"+ DateUtil.getToday4Oclock());
//        //解压文件
////        File zipFile = new File("D:\\hyksj\\"+fileName+"\\" + fileName + "");
////        System.out.println("zipFile:"+zipFile);
////        String path = "D:/hyksj"+fileName+"/";
////        System.out.println("path:"+path);
////        String outPath = unZipFiles(zipFile, path);
////        if (outPath.contains("zip")) {
////            unZipFiles(outPath, path);
////            System.out.println("解压成功");
////        }
////        String ss="[1000002886-20210719110243]交易查询.zip";
////
////        ss=ss.replace("zip","txt");
////        System.out.println("ss:"+ss);
//
//        List<Integer>listss=new ArrayList<>(Arrays.asList(0,1,2,3,4,5));
//        for (Integer integer : listss) {
//            System.out.println(integer.intValue());
//        }
//       String wj=  "[1000002886-20210721170159]交易查询.zip";
//        wj=wj.replace("[","").replace("]","");
//        System.out.println("wj:"+wj);
//
//        String txt="https://crm7cdn.wuuxiang.com/export/zip/files/[1000002886-\"20210722150026\"]交易查询.zip";
//        txt=txt.replace("\"","");
//        System.out.println("txt:"+txt);
//
//        String startTimes=DateUtil.getYesterDayDate()+" 00:00:00";
//        String endTimes=DateUtil.getYesterDayDate()+" 23:59:59";
//
//        System.out.println("startTimes:"+startTimes);
//        System.out.println("endTimes:"+endTimes);
//
//
//        String yesterday = DateUtil.getYesterDay4Oclock();
//        String today = DateUtil.getToday4Oclock();
//        Timestamp yesterdayTime = Timestamp.valueOf(yesterday);
//        Timestamp todayTime = Timestamp.valueOf(today);
//        //获取更新青岛悦荟广场店销售额
//        //构造请求报文
//        StringBuilder soap = new StringBuilder();
//        soap.append(" <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>");
//        //<--Header标头信息start-->
//        soap.append(" <soap:Body>");
//        soap.append(" <postsalescreate xmlns='http://tempurl.org'>");
//        soap.append(" <astr_request>");
//        soap.append(" <header>");
//        //用户名
//        soap.append(" <username>CRMINT</username>");
//        //密码
//        soap.append(" <password>010201</password>");
//        //消息类型
//        soap.append(" <messagetype>SALESDATA</messagetype>");
//        //消息id
//        soap.append(" <messageid>332</messageid>");
//        //版本编号
//        soap.append(" <version>V332M</version>");
//        soap.append(" </header>");
//        //<--Header标头信息end-->
//        //<--SalesTotal:销售单主表start-->
//        soap.append("  <salestotal>");
//        //交易日期
//        //SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
//        String number = DateUtil.getYesterDayTime();
//        String date = number.substring(0, 8);
//        String timess = number.substring(number.length() - 6);
//        String money="111";
//        soap.append(" <txdate_yyyymmdd>" + date + "</txdate_yyyymmdd>");
//        //交易时间
//        soap.append(" <txtime_hhmmss>" + timess + "</txtime_hhmmss>");
//        //商城编号
//        // soap.append(" <mallid>5012</mallid>");
//        //店铺号
//        soap.append(" <storecode>tqd00320</storecode>");
//        //收银机号
//        soap.append(" <tillid>01</tillid>");
//        //销售单号
//        soap.append(" <txdocno>" + number + "</txdocno>");
//        //收银员编号
//        soap.append(" <cashier>001</cashier>");
//        //销售员
//        soap.append(" <salesman></salesman>");
//        //数量
//        soap.append(" </salestotal>");
//        //<--SalesTotal:销售单主表end-->
//        //<--SalesI销售单货品明细表start-->
//        soap.append(" <salesitems>");
//        soap.append(" <salesitem>");
//        //商品编号
//        soap.append(" <itemcode>tqd0032001</itemcode>");
//        //数量
//        soap.append(" <qty>1</qty>");
//        //净金额
//        soap.append(" <netamount>" + money + "</netamount>");
//        soap.append(" </salesitem>");
//        soap.append(" </salesitems>");
//        //<--SalesI销售单货品明细表end-->
//
//        //<!--销售单付款明细表start-->
//        soap.append(" <salestenders>");
//        soap.append(" <salestender>");
//        //付款代码
//        soap.append(" <tendercode>CH</tendercode>");
//        //付款金额
//        soap.append(" <payamount>" + money + "</payamount>");
//        //本位币金额
//        soap.append(" <baseamount>" + money + "</baseamount>");
//        soap.append(" </salestender>");
//        soap.append(" </salestenders>");
//        //<!--SalesTender销售单付款明细表end-->
//
//        soap.append(" </astr_request>");
//        soap.append(" </postsalescreate>");
//        soap.append(" </soap:Body>");
//        soap.append(" </soap:Envelope>");
//        String requestSoap = soap.toString();
//        System.out.println("requestSoap:" + requestSoap);
//        //服务地址(将url替换成自己项目的地址)
//        String serviceAddress = "http://123.234.71.6:8099/ChiaTai/salestrans.asmx?WSDL";
//
//       String urls="https://crm7cdn.wuuxiang.com/export/zip/files/[1000002886-20210726161051]交易查询.zip";
//
//        URL httpUrl=new URL(urls);
//        System.out.println("httpUrl:"+httpUrl);



        String appKey = "ebf8340f8ba7cb0327173299f689c9d8c664b1f4";
        String appSecret = "49c6be3b34eb165ccfa0bb167f6799fe6ed81cc2";
        //String ts="1567483090059";
        String ts = String.valueOf(System.currentTimeMillis());
        String version = "2.0";
        JSONObject json = new JSONObject();

        json.put("couponCode", "77072537235014");
        json.put("vendorShopId", "957299785");
        String four = json.toJSONString();
        String[] params = new String[]{appSecret, "appKey"+appKey, "ts"+ts, "version"+version, four};
        Arrays.sort(params);
        // 将5个参数字符串拼接成一个字符串进行sha1加密
        String clearText = params[0] + params[1] + params[2] + params[3] + params[4];
        String algorithm = "SHA-1";
       String sign = new String(Hex.encodeHex(MessageDigest.getInstance(algorithm).digest((clearText).getBytes()), true));
//        System.out.println("sign:"+sign);

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        HttpEntity<String> formEntity = new HttpEntity<String>(json.toString(), headers);
        String url = "https://open-api.dianping.com/tuangou/coupon/status/query?version="+version+"&appKey="+appKey+"&ts="+ts+"&sign="+sign;
        String result = restTemplate.postForEntity(url, formEntity, String.class).getBody();
        System.out.println("result:"+result);

        Mt mt= restTemplate.postForEntity(url, formEntity, Mt.class).getBody();
        System.out.println("userPhoneTail:"+mt.getContent().getUserPhoneTail());
        /**
         * 美团验券{
         *   "vendorOrderId": "412380809",
         *   "toPayAmount": 28.00,
         *   "orderSkus": [
         *     {
         *       "vendorSkuId": "2006141037019",
         *       "vendorSkuName": "MayDay海鲜茄子煲1份",
         *       "unit": "个",
         *       "unitPrice": 0.1,
         *       "count": 1
         *     }
         *   ],
         *   "couponCode":
         *   "77129208035668",
         *   "vendorShopId": "957299785",
         *   "eId": "5515951",
         *   "eName": "收银员小明"
         * }
         */
//        String orderId=DateUtil.getStampNow();
//        BigDecimal toPayAmount=new BigDecimal(0.1).setScale(2,BigDecimal.ROUND_HALF_UP);
//        String couponCode="77129208035668";
//        String vendorShopId="957299785";
//        String eId="5515951";
//        String eName="收银员小明";
//        MtYqParam.OrderSkusBean orderSkusBean=new MtYqParam.OrderSkusBean();
//        orderSkusBean.setVendorSkuId("2006141037019");
//        orderSkusBean.setVendorSkuName("MayDay海鲜茄子煲1份");
//        orderSkusBean.setUnit("份");
//        orderSkusBean.setUnitPrice(toPayAmount);
//        orderSkusBean.setCount(1);
//        List<MtYqParam.OrderSkusBean> list=new ArrayList<>();
//        list.add(orderSkusBean);
//        JSONObject json1 = new JSONObject();
//
//        json1.put("vendorOrderId",orderId);
//        json1.put("toPayAmount",toPayAmount);
//        json1.put("orderSkus",list);
//        json1.put("couponCode",couponCode);
//        json1.put("vendorShopId",vendorShopId);
//        json1.put("eId",eId);
//        json1.put("eName",eName);
//        String fours = json1.toJSONString();
//        String[] paramss = new String[]{appSecret, "appKey"+appKey, "ts"+ts, "version"+version, fours};
//        Arrays.sort(paramss);
//        // 将5个参数字符串拼接成一个字符串进行sha1加密
//        String clearTexts = paramss[0] + paramss[1] + paramss[2] + paramss[3] + paramss[4];
//        String sign1 = new String(Hex.encodeHex(MessageDigest.getInstance(algorithm).digest((clearTexts).getBytes()), true));
//        System.out.println("sign:"+sign1);
//        String url1="https://open-api.dianping.com/tuangou/coupon/matchConsume?version="+version+"&appKey="+appKey+"&ts="+ts+"&sign="+sign1;
//
//        HttpEntity<String> formEntity1 = new HttpEntity<String>(json1.toString(), headers);
//        String result1 = restTemplate.postForEntity(url1, formEntity1, String.class).getBody();
//        System.out.println("result1:"+result1);
//        JsonParser jp = new JsonParser();
//        //将json字符串转化成json对象
//        JsonObject jo = jp.parse(result1).getAsJsonObject();
//        //获取code对应的值
//        String code = jo.get("code").getAsString();
//        System.out.println("code:"+code);










    }
}
